%                    Draw Airfoil Graphs
%
%
% Created by:  David Gitz (davidgitz@gmail.com
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Written for: AIAA Student Org
%
%             Do not use without explicit permission from
%             either the author or organization this program
%             was written for. Please cite the author for
%             any code/ideas/thought that was borrowed from
%             this work.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

colorOrder = [0 0 0; 0 0 1; 0 1 0; 0 1 1; 1 0 0; 1 0 1; 1 1 0; 1 1 1;];
graphtype = input('For Drag Graphs, press [1].  For Lift Graphs, press [2].');
switch graphtype
    case 1
        XAxisType = input('Independent Axis: Alpha [1] Cl [2] Cd [3] Cspan1 [4] Cspan2 [5] Cspan3 [6] Cspan4 [7]');
        YAxisType = input('Dependent Axis: Alpha [1] Cl [2] Cd [3] Cspan1 [4] Cspan2 [5] Cspan3 [6] Cspan4 [7]');
    case 2
        XAxisType = input('Independent Axis: Alpha [1] Cl [2] Cm [3]');
        YAxisType = input('Dependent Axis: Alpha [1] Cl [2] Cm [3]');
    otherwise
        disp('Try Again')
        
end

for whichFoil = 1:length(myFoils)  %Loop through Airfoils
    fig = figure(whichFoil);
    hold on;
    switch graphtype
        case 1
            for whichRe = 1:length(myFoils(whichFoil).DragData)
                if(whichRe <= length(colorOrder))
                switch XAxisType
                    case 1
                        x = myFoils(whichFoil).DragData(whichRe).alpha;
                    case 2
                        x = myFoils(whichFoil).DragData(whichRe).Cl;
                    case 3
                        x = myFoils(whichFoil).DragData(whichRe).Cd;
                    case 4
                        x = myFoils(whichFoil).DragData(whichRe).Cspan1;
                    case 5
                        x = myFoils(whichFoil).DragData(whichRe).Cspan2;
                    case 6
                        x = myFoils(whichFoil).DragData(whichRe).Cspan3;
                    case 7
                        x = myFoils(whichFoil).DragData(whichRe).Cspan4;
                    otherwise
                end
                switch YAxisType
                    case 1
                        y = myFoils(whichFoil).DragData(whichRe).alpha;
                    case 2
                        y = myFoils(whichFoil).DragData(whichRe).Cl;
                    case 3
                        y = myFoils(whichFoil).DragData(whichRe).Cd;
                    case 4
                        y = myFoils(whichFoil).DragData(whichRe).Cspan1;
                    case 5
                        y = myFoils(whichFoil).DragData(whichRe).Cspan2;
                    case 6
                        y = myFoils(whichFoil).DragData(whichRe).Cspan3;
                    case 7
                        y = myFoils(whichFoil).DragData(whichRe).Cspan4;
                    otherwise
                end
                plot(x,y,'LineWidth',2,'Color',colorOrder(whichRe,:),'DisplayName',num2str(myFoils(whichFoil).DragData(whichRe).Re));
                end
            end
            title(myFoils(whichFoil).name);
            xlabel('Cl')
            ylabel('Cd')
            set(gca,'FontSize',14);
            legend('show')
        case 2
            for whichRe = 1:length(myFoils(whichFoil).LiftData)
                if(whichRe <= length(colorOrder))
                switch XAxisType
                    case 1
                        x = myFoils(whichFoil).LiftData(whichRe).alpha;
                    case 2
                        x = myFoils(whichFoil).LiftData(whichRe).Cl;
                    case 3
                        x = myFoils(whichFoil).LiftData(whichRe).Cm;
                    otherwise
                end
                switch YAxisType
                    case 1
                        y = myFoils(whichFoil).LiftData(whichRe).alpha;
                    case 2
                        y = myFoils(whichFoil).LiftData(whichRe).Cl;
                    case 3
                        y = myFoils(whichFoil).LiftData(whichRe).Cm;
                    otherwise
                end
                plot(x,y,'LineWidth',2,'Color',colorOrder(whichRe,:),'DisplayName',num2str(myFoils(whichFoil).LiftData(whichRe).Re));
                end
            end
            title(myFoils(whichFoil).name);
            xlabel('Cl')
            ylabel('Cd')
            set(gca,'FontSize',14);
            legend('show')
        otherwise
            
    end
    %     for whichRe = 1:length(myFoils(whichFoil).dragData)  %Loop through Reynolds Numbers
    %         if(whichRe <= length(colorOrder))  % More than 8 Reynolds Numbers
    %             %
    %             %             plot(myFoils(whichFoil).dragData(whichRe).Cl,...
    %             %                 myFoils(whichFoil).dragData(whichRe).Cd,...
    %             %                 'LineWidth',2,'Color',colorOrder(whichRe,:),...
    %             %                 'DisplayName',num2str(myFoils(whichFoil).dragData(whichRe).Re));
    %         end
    %     end
    %     title(myFoils(whichFoil).name);
    %     xlabel('Cl')
    %     ylabel('Cd')
    %     set(gca,'FontSize',14);
    %     legend('show')
end

